package com.app.util.collection;

import java.util.LinkedHashMap;
import java.util.Map;

import com.app.util.object.FieldUtil;

public class MapUtil {

	public static Map<String, Object> parseMap(Object obj) {
		Map<String, Object> map = new LinkedHashMap<String, Object>();
		String[] pros = FieldUtil.propertys(obj.getClass());
		for (String pro : pros) {
			map.put(pro, FieldUtil.get(obj, pro));
		}
		return map;
	}

	public static <T> T parseObject(Map map, Class<T> objClass) {
		String[] pros = FieldUtil.propertys(objClass);
		T t;
		try {
			t = objClass.newInstance();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		for (String pro : pros) {
			FieldUtil.set(t, pro, map.get(pro));
		}
		return t;
	}
 
}
